/*
 * $Id: policer.h,v 1.25.2.2 Broadcom SDK $
 * 
 * $Copyright: Copyright 2011 Broadcom Corporation.
 * This program is the proprietary software of Broadcom Corporation
 * and/or its licensors, and may only be used, duplicated, modified
 * or distributed pursuant to the terms and conditions of a separate,
 * written license agreement executed between you and Broadcom
 * (an "Authorized License").  Except as set forth in an Authorized
 * License, Broadcom grants no license (express or implied), right
 * to use, or waiver of any kind with respect to the Software, and
 * Broadcom expressly reserves all rights in and to the Software
 * and all intellectual property rights therein.  IF YOU HAVE
 * NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE
 * IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
 * ALL USE OF THE SOFTWARE.  
 *  
 * Except as expressly set forth in the Authorized License,
 *  
 * 1.     This program, including its structure, sequence and organization,
 * constitutes the valuable trade secrets of Broadcom, and you shall use
 * all reasonable efforts to protect the confidentiality thereof,
 * and to use this information only in connection with your use of
 * Broadcom integrated circuit products.
 *  
 * 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS
 * PROVIDED "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
 * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
 * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY
 * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
 * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
 * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
 * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING
 * OUT OF USE OR PERFORMANCE OF THE SOFTWARE.
 * 
 * 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
 * BROADCOM OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL,
 * INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER
 * ARISING OUT OF OR IN ANY WAY RELATING TO YOUR USE OF OR INABILITY
 * TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF
 * THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR USD 1.00,
 * WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING
 * ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.$
 * 
 * DO NOT EDIT THIS FILE!
 * This file is auto-generated.
 * Edits to this file will be lost when it is regenerated.
 */

#ifndef __BCM_POLICER_H__
#define __BCM_POLICER_H__

#include <bcm/types.h>

/* Policer Modes. */
typedef enum bcm_policer_mode_e {
    bcmPolicerModeSrTcm,            /* RFC 2697 */
    bcmPolicerModeCommitted, 
    bcmPolicerModePeak, 
    bcmPolicerModeTrTcm,            /* RFC 2698 */
    bcmPolicerModeTrTcmDs,          /* RFC 4115 */
    bcmPolicerModeGreen, 
    bcmPolicerModePassThrough, 
    bcmPolicerModeSrTcmModified, 
    bcmPolicerModeCoupledTrTcmDs, 
    bcmPolicerModeCascade, 
    bcmPolicerModeCoupledCascade, 
    bcmPolicerModeCount 
} bcm_policer_mode_t;

/* Modes for creating a group of policers */
typedef enum bcm_policer_group_mode_e {
    bcmPolicerGroupModeSingle,          /* A single policer used for all traffic
                                           types */
    bcmPolicerGroupModeTrafficType,     /* A dedicated policer per traffic type
                                           unicast, multicast, broadcast */
    bcmPolicerGroupModeDlfAll,          /* A pair of policers where the base
                                           policer is used for dlf and the other
                                           policer is used for all traffic types */
    bcmPolicerGroupModeDlfIntPri,       /* N+1 policers where the base policer
                                           is used for dlf and next N are used
                                           per Cos */
    bcmPolicerGroupModeTyped,           /* A dedicated policer for unknown
                                           unicast, known unicast, multicast,
                                           broadcast */
    bcmPolicerGroupModeTypedAll,        /* A dedicated policer for unknown
                                           unicast, known unicast, multicast,
                                           broadcast and one for all traffic
                                           (not already policed) */
    bcmPolicerGroupModeTypedIntPri,     /* A dedicated policer for unknown
                                           unicast, known unicast, multicast,
                                           broadcast and N internal priority
                                           policers for traffic (not already
                                           policed) */
    bcmPolicerGroupModeSingleWithControl, /* A single policer used for all traffic
                                           types with an additional policer for
                                           control traffic */
    bcmPolicerGroupModeTrafficTypeWithControl, /* A dedicated policer per traffic type
                                           unicast, multicast, broadcast with an
                                           additional policer for control
                                           traffic */
    bcmPolicerGroupModeDlfAllWithControl, /* A pair of policers where the base
                                           policer is used for control, the next
                                           one for dlf and the other policer is
                                           used for all traffic types */
    bcmPolicerGroupModeDlfIntPriWithControl, /* N+2 policers where the base policer
                                           is used for control, the next one for
                                           dlf and next N are used per Cos */
    bcmPolicerGroupModeTypedWithControl, /* A dedicated policer for control,
                                           unknown unicast, known unicast,
                                           multicast, broadcast */
    bcmPolicerGroupModeTypedAllWithControl, /* A dedicated policer for control,
                                           unknown unicast, known unicast,
                                           multicast, broadcast and one for all
                                           traffic (not already policed) */
    bcmPolicerGroupModeTypedIntPriWithControl, /* A dedicated policer for control,
                                           unknown unicast, known unicast,
                                           multicast, broadcast and N internal
                                           priority policers for traffic (not
                                           already policed) */
    bcmPolicerGroupModeDot1P,           /* A Set of 8 policers based on Vlan
                                           priority */
    bcmPolicerGroupModeIntPri,          /* A Set of 16 policers based on
                                           internal priority */
    bcmPolicerGroupModeIntPriCng,       /* A Set of 64 policers based on
                                           internal priority and cng */
    bcmPolicerGroupModeSvpType,         /* A Set of 2 policers based on SVP type */
    bcmPolicerGroupModeDscp,            /* A Set of 64 policers based on IP DSCP
                                           bits */
    bcmPolicerGroupModeCascade,         /*  User specified set of policers(max
                                           8), wherein excess bandwidth can
                                           overflow from high priority bucket to
                                           low priority bucket */
    bcmPolicerGroupModeCascadeWithCoupling /*  User specified set of policers(max
                                           4), wherein excess bandwidth can
                                           overflow from high priority bucket to
                                           low priority bucket and from low
                                           priority green bucket to high
                                           priority yellow bucket */
} bcm_policer_group_mode_t;

/* Supported policer stats */
typedef enum bcm_policer_stat_e {
    bcmPolicerStatGreenToGreenPackets,  /* Packet count for G-To-G transitions */
    bcmPolicerStatGreenToGreenBytes,    /* Byte count for G-To-G transitions */
    bcmPolicerStatGreenToYellowPackets, /* Packet count for G-To-Y transitions */
    bcmPolicerStatGreenToYellowBytes,   /* Byte count for G-To-Y transitions */
    bcmPolicerStatGreenToRedPackets,    /* Packet count for G-To-R transitions */
    bcmPolicerStatGreenToRedBytes,      /* Byte count for G-To-R transitions */
    bcmPolicerStatGreenToDropPackets,   /* Packet count for G-To-D transitions */
    bcmPolicerStatGreenToDropBytes,     /* Byte count for G-To-D transitions */
    bcmPolicerStatYellowToGreenPackets, /* Packet count for Y-To-G transitions */
    bcmPolicerStatYellowToGreenBytes,   /* Byte count for Y-To-G transitions */
    bcmPolicerStatYellowToYellowPackets, /* Packet count for Y-To-Y transitions */
    bcmPolicerStatYellowToYellowBytes,  /* Byte count for Y-To-Y transitions */
    bcmPolicerStatYellowToRedPackets,   /* Packet count for Y-To-R transitions */
    bcmPolicerStatYellowToRedBytes,     /* Byte count for Y-To-R transitions */
    bcmPolicerStatYellowToDropPackets,  /* Packet count for Y-To-D transitions */
    bcmPolicerStatYellowToDropBytes,    /* Byte count for Y-To-D transitions */
    bcmPolicerStatRedToGreenPackets,    /* Packet count for R-To-G transitions */
    bcmPolicerStatRedToGreenBytes,      /* Byte count for R-To-G transitions */
    bcmPolicerStatRedToYellowPackets,   /* Packet count for R-To-Y transitions */
    bcmPolicerStatRedToYellowBytes,     /* Byte count for R-To-Y transitions */
    bcmPolicerStatRedToRedPackets,      /* Packet count for R-To-R transitions */
    bcmPolicerStatRedToRedBytes,        /* Byte count for R-To-R transitions */
    bcmPolicerStatRedToDropPackets,     /* Packet count for R-To-D transitions */
    bcmPolicerStatRedToDropBytes,       /* Byte count for R-To-D transitions */
    bcmPolicerStatPackets,              /* Packet count for all types of traffic
                                           policed */
    bcmPolicerStatBytes,                /* Byte count for all types of traffic
                                           policed */
    bcmPolicerStatUnknownUnicastPackets, /* Packet count for policed unknown
                                           unicast traffic */
    bcmPolicerStatUnknownUnicastBytes,  /* Byte count for policed unknown
                                           unicast traffic */
    bcmPolicerStatUnicastPackets,       /* Packet count for policed unicast
                                           traffic */
    bcmPolicerStatUnicastBytes,         /* Byte count for policed unicast
                                           traffic */
    bcmPolicerStatMulticastPackets,     /* Packet count for policed multicast
                                           traffic */
    bcmPolicerStatMulticastBytes,       /* Byte count for policed multicast
                                           traffic */
    bcmPolicerStatBroadcastPackets,     /* Packet count for policed broadcast
                                           traffic */
    bcmPolicerStatBroadcastBytes,       /* Byte count for policed broadcast
                                           traffic */
    bcmPolicerStatDropPackets,          /* Packet count for all types of traffic
                                           dropped */
    bcmPolicerStatDropBytes,            /* Byte count for all types of traffic
                                           dropped */
    bcmPolicerStatDropUnknownUnicastPackets, /* Packet count for dropped unknown
                                           unicast traffic */
    bcmPolicerStatDropUnknownUnicastBytes, /* Byte count for dropped unknown
                                           unicast traffic */
    bcmPolicerStatDropUnicastPackets,   /* Packet count for dropped unicast
                                           traffic */
    bcmPolicerStatDropUnicastBytes,     /* Byte count for dropped unicast
                                           traffic */
    bcmPolicerStatDropMulticastPackets, /* Packet count for dropped multicast
                                           traffic */
    bcmPolicerStatDropMulticastBytes,   /* Byte count for dropped multicast
                                           traffic */
    bcmPolicerStatDropBroadcastPackets, /* Packet count for dropped broadcast
                                           traffic */
    bcmPolicerStatDropBroadcastBytes,   /* Byte count for dropped broadcast
                                           traffic */
    bcmPolicerStatGreenPackets,         /* Packet count for traffic marked green */
    bcmPolicerStatGreenBytes,           /* Byte count for traffic marked green */
    bcmPolicerStatYellowPackets,        /* Packet count for traffic marked
                                           yellow */
    bcmPolicerStatYellowBytes,          /* Byte count for traffic marked yellow */
    bcmPolicerStatRedPackets,           /* Packet count for traffic marked red */
    bcmPolicerStatRedBytes,             /* Byte count for traffic marked red */
    bcmPolicerStatCount                 /* Always last */
} bcm_policer_stat_t;

#define BCM_POLICER_WITH_ID         0x00000001 
#define BCM_POLICER_REPLACE         0x00000002 
#define BCM_POLICER_COLOR_BLIND     0x00000004 
#define BCM_POLICER_DROP_RED        0x00000008 
#define BCM_POLICER_COLOR_MERGE_OR  0x00000010 

#define BCM_POLICER_GLOBAL_METER_SHARING_MODE_MIN 0x00000000 
#define BCM_POLICER_GLOBAL_METER_SHARING_MODE_MAX 0x00000001 
#define BCM_POLICER_GLOBAL_METER_SHARING_MODE_MIN_MAX 0x00000002 

#define BCM_POLICER_GLOBAL_METER_ENVELOP_MICRO_FLOW 0x1        
#define BCM_POLICER_GLOBAL_METER_ENVELOP_MACRO_FLOW 0x2        

typedef struct bcm_policer_config_s {
    uint32 flags;               /* Service VLAN TPID value. */
    bcm_policer_mode_t mode;    /* Policer mode. */
    uint32 ckbits_sec;          /* Committed rate. */
    uint32 ckbits_burst;        /* Committed burst size. */
    uint32 pkbits_sec;          /* Peak rate. */
    uint32 pkbits_burst;        /* Peak burst size. */
    uint32 kbits_current;       /* Current size. */
    uint32 action_id;           /* Index of the global meter action entry */
    uint32 sharing_mode;        /* Meter sharing mode in case of Macro meter of
                                   Envelop */
} bcm_policer_config_t;

/* Initialize a policer config structure. */
extern void bcm_policer_config_t_init(
    bcm_policer_config_t *pol_cfg);

#ifndef BCM_HIDE_DISPATCHABLE

/* Initialize policer module. */
extern int bcm_policer_init(
    int unit);

/* Create a policer entry. */
extern int bcm_policer_create(
    int unit, 
    bcm_policer_config_t *pol_cfg, 
    bcm_policer_t *policer_id);

/* Destroy a policer entry. */
extern int bcm_policer_destroy(
    int unit, 
    bcm_policer_t policer_id);

/* Destroy all policer entries. */
extern int bcm_policer_destroy_all(
    int unit);

/* Set the config settings for a policer entry. */
extern int bcm_policer_set(
    int unit, 
    bcm_policer_t policer_id, 
    bcm_policer_config_t *pol_cfg);

/* Get the config settings for a policer entry. */
extern int bcm_policer_get(
    int unit, 
    bcm_policer_t policer_id, 
    bcm_policer_config_t *pol_cfg);

#endif /* BCM_HIDE_DISPATCHABLE */

typedef int (*bcm_policer_traverse_cb)(
    int unit, 
    bcm_policer_t policer_id, 
    bcm_policer_config_t *info, 
    void *user_data);

#ifndef BCM_HIDE_DISPATCHABLE

/* 
 * Traverse all existing policer entries and call supplied callback
 * function.
 */
extern int bcm_policer_traverse(
    int unit, 
    bcm_policer_traverse_cb cb, 
    void *user_data);

/* 
 * Allocate a block of policer entries. Note that bcm_policer_set must be
 * called to setup the individual policers.
 */
extern int bcm_policer_group_create(
    int unit, 
    bcm_policer_group_mode_t mode, 
    bcm_policer_t *policer_id, 
    int *npolicers);

/* 
 * Allocate a policer for envelop meter. Depending on the flag a micro or
 * a macro meter is allocated. Note that bcm_policer_set must be called
 * to setup the individual policers.
 */
extern int bcm_policer_envelop_create(
    int unit, 
    uint32 flag, 
    bcm_policer_t macro_flow_policer_id, 
    bcm_policer_t *policer_id);

/* 
 * Checks if statistics collection is enabled on the specified policer
 * id.
 */
extern int bcm_policer_stat_enable_get(
    int unit, 
    bcm_policer_t policer_id, 
    int *enable);

/* Enables statistics collection on the specified policer id. */
extern int bcm_policer_stat_enable_set(
    int unit, 
    bcm_policer_t policer_id, 
    int enable);

/* Gets the specified stat */
extern int bcm_policer_stat_get(
    int unit, 
    bcm_policer_t policer_id, 
    bcm_cos_t int_pri, 
    bcm_policer_stat_t stat, 
    uint64 *value);

/* 32bit version of stat get API */
extern int bcm_policer_stat_get32(
    int unit, 
    bcm_policer_t policer_id, 
    bcm_cos_t int_pri, 
    bcm_policer_stat_t stat, 
    uint32 *value);

/* Sets the specified stat */
extern int bcm_policer_stat_set(
    int unit, 
    bcm_policer_t policer_id, 
    bcm_cos_t int_pri, 
    bcm_policer_stat_t stat, 
    uint64 value);

/* 32bit version of stat set API */
extern int bcm_policer_stat_set32(
    int unit, 
    bcm_policer_t policer_id, 
    bcm_cos_t int_pri, 
    bcm_policer_stat_t stat, 
    uint32 value);

/* Attach policer action to a policer id */
extern int bcm_policer_action_attach(
    int unit, 
    bcm_policer_t policer_id, 
    uint32 action_id);

/* detach policer action from a policer id */
extern int bcm_policer_action_detach(
    int unit, 
    bcm_policer_t policer_id, 
    uint32 action_id);

/* Get the action id associated with a policer id */
extern int bcm_policer_action_attach_get(
    int unit, 
    bcm_policer_t policer_id, 
    uint32 *action_id);

#endif /* BCM_HIDE_DISPATCHABLE */

/* Global meter policer actions */
typedef enum bcm_policer_action_e {
    bcmPolicerActionGpDrop,         /* Green priority drop */
    bcmPolicerActionGpDscpNew,      /* Green packet change DSCP value param0:
                                       New DSCP value */
    bcmPolicerActionGpEcnNew,       /* Green packet change ECN value param0: New
                                       ECN value */
    bcmPolicerActionGpPrioIntNew,   /* Green packet internal priority from an
                                       argument. param0: New priority */
    bcmPolicerActionGpCngNew,       /* Green packet change CNG to 00 */
    bcmPolicerActionGpVlanPrioNew,  /* Green packet change vlan priority.
                                       param0: New priority */
    bcmPolicerActionYpDrop,         /* Yellow priority drop */
    bcmPolicerActionYpDscpNew,      /* Yellow packet change DSCP value param0:
                                       New DSCP value */
    bcmPolicerActionYpEcnNew,       /* Yellow packet change ECN value param0:
                                       New ECN value */
    bcmPolicerActionYpPrioIntNew,   /* Yellow packet internal priority from an
                                       argument. param0: New priority */
    bcmPolicerActionYpCngNew,       /* Yellow packet change CNG to 01 */
    bcmPolicerActionYpVlanPrioNew,  /* Yellow packet change vlan priority.
                                       param0: New priority */
    bcmPolicerActionRpDrop,         /* Red priority drop */
    bcmPolicerActionRpDscpNew,      /* Red packet change DSCP value param0: New
                                       DSCP value */
    bcmPolicerActionRpEcnNew,       /* Red packet change ECN value param0: New
                                       ECN value */
    bcmPolicerActionRpPrioIntNew,   /* Red packet internal priority from an
                                       argument. param0: New priority */
    bcmPolicerActionRpCngNew,       /* Red packet change CNG to 11 */
    bcmPolicerActionRpVlanPrioNew   /* Red packet change vlan priority. param0:
                                       New priority */
} bcm_policer_action_t;

#ifndef BCM_HIDE_DISPATCHABLE

/* Create a new action entry in global meter action table */
extern int bcm_policer_action_create(
    int unit, 
    uint32 *action_id);

/* Delete an entry from meter action table */
extern int bcm_policer_action_destroy(
    int unit, 
    uint32 action_id);

/* Add an action to global meter action table entry */
extern int bcm_policer_action_add(
    int unit, 
    uint32 action_id, 
    bcm_policer_action_t action, 
    uint32 param0);

/* get action parameter for a given action */
extern int bcm_policer_action_get(
    int unit, 
    uint32 action_id, 
    bcm_policer_action_t action, 
    uint32 *param0);

#endif /* BCM_HIDE_DISPATCHABLE */

#endif /* __BCM_POLICER_H__ */
